/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

:host {
    --spectrum-clear-button-background-color: var(--system-clear-button-background-color);
    --spectrum-clear-button-background-color-hover: var(--system-clear-button-background-color-hover);
    --spectrum-clear-button-background-color-down: var(--system-clear-button-background-color-down);
    --spectrum-clear-button-background-color-key-focus: var(--system-clear-button-background-color-key-focus);
}

:host([static-color="white"]) {
    --spectrum-clear-button-background-color-hover: var(--system-clear-button-static-white-background-color-hover);
    --spectrum-clear-button-background-color-down: var(--system-clear-button-static-white-background-color-down);
    --spectrum-clear-button-background-color-key-focus: var(--system-clear-button-static-white-background-color-key-focus);
}

:host {
    --spectrum-clear-button-height: var(--spectrum-component-height-100);
    --spectrum-clear-button-width: var(--spectrum-component-height-100);
    --spectrum-clear-button-padding: var(--spectrum-in-field-button-edge-to-fill);
    --spectrum-clear-button-icon-color: var(--spectrum-neutral-content-color-default);
    --spectrum-clear-button-icon-color-hover: var(--spectrum-neutral-content-color-hover);
    --spectrum-clear-button-icon-color-down: var(--spectrum-neutral-content-color-down);
    --spectrum-clear-button-icon-color-key-focus: var(--spectrum-neutral-content-color-key-focus);

    box-sizing: border-box;
    block-size: var(--mod-clear-button-height, var(--spectrum-clear-button-height));
    inline-size: var(--mod-clear-button-width, var(--spectrum-clear-button-width));
    background-color: var(--mod-clear-button-background-color, transparent);
    padding: var(--mod-clear-button-padding, var(--spectrum-clear-button-padding));
    color: var(--mod-clear-button-icon-color, var(--spectrum-clear-button-icon-color));
    border: none;
    border-radius: 100%;
    margin: 0;
}

:host([size="s"]) {
    --spectrum-clear-button-height: var(--spectrum-component-height-75);
    --spectrum-clear-button-width: var(--spectrum-component-height-75);
}

:host([size="l"]) {
    --spectrum-clear-button-height: var(--spectrum-component-height-200);
    --spectrum-clear-button-width: var(--spectrum-component-height-200);
}

:host([size="xl"]) {
    --spectrum-clear-button-height: var(--spectrum-component-height-300);
    --spectrum-clear-button-width: var(--spectrum-component-height-300);
}

:host([quiet]) {
    --mod-clear-button-background-color: transparent;
    --mod-clear-button-background-color-hover: transparent;
    --mod-clear-button-background-color-down: transparent;
    --mod-clear-button-background-color-key-focus: transparent;
}

:host([static-color="white"]) {
    --mod-clear-button-icon-color: var(--spectrum-white);
    --mod-clear-button-icon-color-hover: var(--spectrum-white);
    --mod-clear-button-icon-color-down: var(--spectrum-white);
    --mod-clear-button-icon-color-key-focus: var(--spectrum-white);
    --mod-clear-button-icon-color-disabled: var(--spectrum-disabled-static-white-content-color);
    --mod-clear-button-background-color: transparent;
}

:host(:disabled),
:host([disabled]) {
    --mod-clear-button-icon-color: var(--mod-clear-button-icon-color-disabled, var(--spectrum-disabled-content-color));
    --mod-clear-button-icon-color-hover: var(--spectrum-disabled-content-color);
    --mod-clear-button-icon-color-down: var(--spectrum-disabled-content-color);
    --mod-clear-button-background-color: var(--mod-clear-button-background-color-disabled, transparent);
}

:host(:not(:disabled)),
:host(:not([disabled])) {
    cursor: pointer;
}

.icon {
    margin-block: 0;
    margin-inline: auto;
}

@media (hover: hover) {
    :host(:hover:not(:disabled)),
    :host(:hover:not([disabled])) {
        color: var(--highcontrast-clear-button-icon-color-hover, var(--mod-clear-button-icon-color-hover, var(--spectrum-clear-button-icon-color-hover)));
    }

    :host(:hover:not(:disabled)) .fill,
    :host(:hover:not([disabled])) .fill {
        background-color: var(--mod-clear-button-background-color-hover, var(--spectrum-clear-button-background-color-hover));
    }
}

:host(:is(:active, [active]):not(:disabled)),
:host(:is(:active, [active]):not([disabled])) {
    color: var(--mod-clear-button-icon-color-down, var(--spectrum-clear-button-icon-color-down));
}

:host(:is(:active, [active]):not(:disabled)),
:host(:is(:active, [active]):not([disabled])) .fill {
    background-color: var(--mod-clear-button-background-color-down, var(--spectrum-clear-button-background-color-down));
}

:host(:not(:disabled):focus-visible),
:host(:not([disabled]):focus-visible),
:host(:not(:disabled):focus-within),
:host(:not([disabled]):focus-within) {
    color: var(--mod-clear-button-icon-color-key-focus, var(--spectrum-clear-button-icon-color-key-focus));
}

:host(:not(:disabled):focus-visible) .fill,
:host(:not([disabled]):focus-visible) .fill,
:host(:not(:disabled):focus-within) .fill,
:host(:not([disabled]):focus-within) .fill {
    background-color: var(--mod-clear-button-background-color-key-focus, var(--spectrum-clear-button-background-color-key-focus));
}

.icon {
    color: inherit;
}

.fill {
    background-color: var(--mod-clear-button-background-color, var(--spectrum-clear-button-background-color));
    inline-size: 100%;
    block-size: 100%;
    border-radius: 100%;
    justify-content: center;
    align-items: center;
    display: flex;
}

:host([variant="overBackground"]:focus-visible),
:host([static-color="white"]:focus-visible) {
    outline: none;
}

@media (forced-colors: active) {
    :host(:not(:disabled)),
    :host(:not([disabled])) {
        --highcontrast-clear-button-icon-color-hover: Highlight;
    }
}
